
app.controller('txDataCtrl', ['$scope', function($scope) {
	var needNewPagination = true;
	getData(1);
	
	function getData(pageNo) {
		var state = $("#tx-state").val();
		var userKey = $.trim($("#userKey").val());
		var minMoney = $.trim($("#minMoney").val());
		var maxMoney = $.trim($("#maxMoney").val());
		var txAccount = $.trim($("#txAccount").val());
		var realName = $.trim($("#realName").val());
		var startTimeA = $.trim($("#startTimeA").val());
		var endTimeA = $.trim($("#endTimeA").val());
		var startTimeD = $.trim($("#startTimeD").val());
		var endTimeD = $.trim($("#endTimeD").val());
		var zzAccount = $.trim($("#zzAccount").val());
		var operator = $.trim($("#operator").val());
		var info = $.trim($("#info").val());
		
		var param = {
			state: state,
			userKey: userKey,
			minMoney: minMoney,
			maxMoney: maxMoney,
			txAccount: txAccount,
			realName: realName,
			startTimeA: startTimeA,
			endTimeA: endTimeA,
			startTimeD: startTimeD,
			endTimeD: endTimeD,
			zzAccount: zzAccount,
			operator: operator,
			info: info,
			pageNo: pageNo,
			pageCount: 10,
		};
		AQ.callAQJSON("getTxData.do", param, function(result) {
			var data = result.data;
			$scope.$apply(function () {
				$scope.listData = data;
				if(pageNo == 1 && needNewPagination) {	//创建分页
					var num_entries = 100;
					Utils.newPagination("Pagination", num_entries, function(page_index, jq) {
						if(page_index == 0 && needNewPagination) {
							needNewPagination = false;
							return;
						}
						getData(page_index+1);
					});
				}
			});
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
	}
	
	$("#query-data").click(function() {
        getData(1);
    });
	
	$scope.handleTx = function (id, userId, money, txAccount, realName) {
		var content = '<input type="text" style="color:#B00606; border:1px dashed #D9D9D9; font-weight:bold; font-size:22px; width:320px; cursor:text;" onclick="select();" readOnly="true" value="'+ txAccount +'"/>' +
				'<div style="height:10px"></div><span style="font-size:18px; font-weight:bold;">'+ realName +'</span><BR>' +
				'<input type="text" style="color:#E41; border:1px dashed #D9D9D9; font-weight:bold; font-size:50px; width:180px; cursor:text;" onclick="select();" readOnly="true" value="'+ money +'"/>' +
				'<span style="color:#E41; font-weight:bold; margin-left:10px;">'+ RMB.toChinese(money) +'</span><BR><BR>' +
				'转账账户：<input type="text" id="item-zzAccount" value="fzwpay@163.com" placeholder="必填" style="border:1px solid #CCC; width:220px; height:25px; padding-left:5px;"/><BR>' +
				'备注：<textarea id="item-info" style="border:1px solid #CCC; width:252px; height:40px;"></textarea>';
		Utils.checkDialog(content, "确定已转账", "返回", function() {
			var zzAccount = $.trim($("#item-zzAccount").val());
			var info = $.trim($("#item-info").val());
			
			var param = {
				id: id,
				userId: userId,
				zzAccount: zzAccount,
				info: info,
			};
			AQ.callAQJSON("handleTx.do", param, function(result) {
				$("#ID_"+id).parent("ul").remove();
			}, function(err, code) {
				Utils.msgDialog(err + "["+ code +"]");
			});
		}, function() {});
	}

}]);
